/**
 * 万里汇CNY计算汇率表
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
    console.log('------$scope.menuId1-----', $scope.menuId);
    console.log('------$scope.buttonArr1-----', $scope.buttonArr);

    $scope.bindBtn = function(event) {
        var datas = $scope.getSelectedRows();
        switch(event){
            case 'event-to-add':
            {
                window.top.add_tab("万里汇CNY计算汇率表 - 新增","/web/finance/tcwWanliExchangeRate/toAdd");
                break;
            }
            case 'event-to-edit':
            {
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else if(datas.length > 1) {
                    layer.alert('只能选中一行数据');
                } else {
                    window.top.add_tab("万里汇CNY计算汇率表 - 编辑","/web/finance/tcwWanliExchangeRate/toEdit?id="+ datas[0].id);
                }
                break;
            }
            case 'event-to-export'://导出
            {
                $scope.doExport('/api/inter/tcwWanliExchangeRate/export');
                break;
            }
            case 'event-to-updateExchangeRate'://导入当日汇率
            {
                layer.open({
                    shadeClose:true,
                    title: '请选择汇率计算的时间区间',
                    content: `
								<form class="layui-form">
								  <div class="layui-form-item">
									 <div class="layui-inline">
										  <label class="layui-form-label">日期范围</label>
										  <div class="layui-inline" id="ID-laydate-range">
											<div class="layui-input-inline">
											  <input type="text" autocomplete="off" id="ID-laydate-start-date" class="layui-input" placeholder="开始日期">
											</div>
											<div class="layui-form-mid">-</div>
											<div class="layui-input-inline">
											  <input type="text" autocomplete="off" id="ID-laydate-end-date" class="layui-input" placeholder="结束日期">
											</div>
										  </div>
										</div>
								  </div>
								</form>
							`,
                    success: function(layero, index) {},
                    yes: function (index, layero) {
                        var countTimeStart = $('#ID-laydate-start-date').val();
                        var countTimeEnd = $('#ID-laydate-end-date').val();
                        if(countTimeStart==undefined || countTimeStart==null || countTimeStart==''){
                            return  layer.alert('尚未选中开始日期');
                        }
                        if(countTimeEnd==undefined || countTimeEnd==null || countTimeEnd==''){
                            return layer.alert('尚未选中结束日期');
                        }
                        layer.msg('处理中', {
                            icon: 16,shade: 0.01
                        });
                        $http.post('/api/inter/tcwWanliExchangeRate/updateExchangeRate', {}, {params: {countTimeStart:countTimeStart,countTimeEnd:countTimeEnd}})
                            .success(function (data) {
                                if (data.code == 0) {
                                    layer.closeAll();
                                    layer.msg("导入成功");
                                    setTimeout(function(){
                                        location.reload();
                                    }, 3000);
                                } else {
                                    layer.msg(data.msg);
                                }
                            })
                            .error(function(result){
                                layer.closeAll();
                                layer.msg("导入失败，请稍后再试！", {icon: 2});
                            });
                    }
                });
                layui.use(function(){
                    var nowTime=new Date();
                    var laydate = layui.laydate;
                    // 日期范围 - 左右面板联动选择模式
                    laydate.render({
                        elem: '#ID-laydate-range',
                        range: ['#ID-laydate-start-date', '#ID-laydate-end-date'],
                        max:0,
                    });
                });
                break;
            }


        };
    }
}


//表格双击
app.controller('dbClickCtrl', ['$scope', '$http', DbClickController]);
function DbClickController($scope, $http){
    $scope.doubleClick = function(data) {
        window.top.add_tab('万里汇CNY计算汇率表 - 详情','/web/finance/tcwWanliExchangeRate/toDetail?id=' + data.id);
    }
}



